<template>
	<view class="content bgf8">
		<view class="boxes" v-for="i in list" @click.stop="detail(i)">
			<view class="uniFlex2"><text class="title">收货地址：</text>{{i.province_name}}{{i.city_name}}{{i.area_name}}</view>
			<view class="uniFlex2"><text class="title">详细地址：</text>{{i.address}}</view>
			<view class="uniFlex2"><text class="title">收货人姓名：</text>{{i.name}}</view>
			<view class="uniFlex2"><text class="title">收货人电话：</text>{{i.phone}}</view>
			
			<view class="uniBtn">
				<view></view>
				<view class="text" @click.stop="bianji(i)">编辑</view>
			</view>
		</view>
		<view style="margin: 30upx;text-align: center;" v-if="list.length == 0">无数据，请添加</view>
		<drag-button :isDock="true" @btnClick="btnClick"/>
	</view>
</template>

<script>
	import {
		address
	} from '@/request/api.js'
	import dragButton from "@/components/drag-button/drag-button.vue";
	export default {
		components: {
			dragButton
		},
		data() {
			return {
				list:[]
			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			getList() {
				address().then(res => {
					this.list = res.data
				})
			},
			detail(i){
				let pages = getCurrentPages(); // 当前页面
				let beforePage = pages[pages.length - 2]; // 前一个页面
				// console.log(beforePage.route)
				if (beforePage.route == 'pages/myCode/pay') {
					beforePage.$vm.message = i//替换上个页面参数
					uni.navigateBack()
				} else {
					uni.navigateTo({
						url:'./update?items='+JSON.stringify(i)
					})
				}
			},
			bianji(i){
				uni.navigateTo({
					url:'./update?items='+JSON.stringify(i)
				})
			},
			btnClick(){
				console.log('添加')
				uni.navigateTo({
					url:'./add'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background: #f8f8f8;
	}
	.boxes{
		padding: 30upx;
		background: #ffffff;
		margin-bottom: 20upx;
		line-height: 170%;
		font-size: 28upx;
		color: #7B7B7B;
		
		.title{
			flex-shrink: 0;
			color: #000000;
		}
		.text{
			color: #F87F53;
			padding: 5upx 20upx;
			font-size: 30upx;
		}
	}
</style>
